package com.xyh.springboot.exception;

import com.xyh.springboot.util.BaseInfoInterface;
import lombok.Data;

/**
 * @Author:kyle
 * @Date:2020/12/28 - 17:27
 * @Project:springboot
 * @Package:com.xyh.springboot.exception
 * @Version:1.0
 * 最终，自定义异常处理
 * 为了更加适用前后端分离的应用设置，将异常处理和之前的返回前端`ResultVO`的信息再进行了一下封装
 */

@Data
public class BizException extends RuntimeException{

    private Integer status;
    private String message;

    public BizException() {
    }

    public BizException(String message) {
        super(message);
        this.message = message;
    }

    public BizException(Integer status,String message) {
        super(status +"");
        this.status = status;
        this.message = message;
    }

    public BizException(BaseInfoInterface baseInfoInterface) {//可以传枚举
        super(baseInfoInterface.status()+"");
        this.status = baseInfoInterface.status();
        this.message = baseInfoInterface.message();
    }

    public BizException(BaseInfoInterface baseInfoInterface, Throwable cause) {
        super(baseInfoInterface.message(), cause);
        this.status = baseInfoInterface.status();
        this.message = baseInfoInterface.message();
    }
}
